đź”’ Password-Protected LED Vault

We used a tool called ChatGPT to help us come up with this project. Like all AI tools, it doesn't always get it right so thanks for being our testers!!

Welcome to the Password-Protected LED Vault project! You’ll build a system using a Raspberry Pi Pico, LEDs, and buttons. Let’s dive in and code it line by line!

Step 1: Import Required Libraries

In Python, we can use special libraries to make controlling the Pico easier. Let’s add the first line of code:

from machine import Pin

What does this do?

Step 2: Add a Delay Function

Sometimes we need to pause the program for a short time. Let’s add this line:

from time import sleep

What does this do?

🌟 Great work! You’ve set up the libraries. Let’s move on to controlling the LED and buttons.

Step 3: Set Up the LED

Now we’ll set up the LED so the Pico can control it. Add this line:

led = Pin(15, Pin.OUT)

What does this do?

Step 4: Set Up Buttons

Let’s add two buttons. Each will send a signal to the Pico when pressed:

button1 = Pin(14, Pin.IN, Pin.PULL_DOWN)

What does this do?

Now add the second button:

button0 = Pin(13, Pin.IN, Pin.PULL_DOWN)

What does this do?

🎉 Fantastic! You’ve connected the LED and buttons. Let’s start coding the password logic!

Step 5: Create a Password Function

Let’s create a function to handle passwords. Add this code:

def check_password(): entered_password = [] # Stores what the user enters correct_password = [1, 0, 1] # The secret password

What does this do?

Step 6: Add Button Logic

Inside the function, add this loop to record button presses:

while len(entered_password) < len(correct_password): if button1.value() == 1: entered_password.append(1) sleep(0.3) # Prevents double presses elif button0.value() == 1: entered_password.append(0) sleep(0.3)

What does this do?

Step 7: Check the Password

Finally, add this code to check if the password is correct:

if entered_password == correct_password: led.value(1) # Turn on the LED print("Access Granted!") else: print("Access Denied!") entered_password.clear() # Reset password

What does this do?

🚀 You’ve built the full program! Save it as main.py on your Pico and test it by entering the password (1, 0, 1).